﻿using System.Collections.ObjectModel;
using BlueDot.Data.Core;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServerCe;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Syncronization;
using Syncronization.REST;

namespace SmartDevice.Syncronization.UnitTests
{
    /// <summary>
    /// Summary description for RestSyncProviderFixture
    /// </summary>
    [TestClass]
    public class RestSyncProviderFixture
    {
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #region Tests

        [TestMethod]
        public void CanGetSchema()
        {
            var syncProvider = new RestSyncProvider();
            var clientProvider = new SqlCeClientSyncProvider("Data Source = Test.sdf", true);

            var schemaBuilder1 = new TestSchemaBuilder {Name = "test1"};
            schemaBuilder1.AddColumn(new DataStoreColumnSchema
                                         {
                                             Name = "ID",
                                             IsUniqueKey = true,
                                             IsRequired = true,
                                             ClrDataType = typeof (int)
                                         });

            schemaBuilder1.AddColumn(new DataStoreColumnSchema
                                         {
                                             Name = "Col1",
                                             IsUniqueKey = false,
                                             IsRequired = true,
                                             ClrDataType = typeof (string),
                                             MaxLength = 20
                                         });

            schemaBuilder1.AddColumn(new DataStoreColumnSchema
                                         {
                                             Name = "Col2",
                                             IsUniqueKey = false,
                                             IsRequired = false,
                                             ClrDataType = typeof (string),
                                             MaxLength = 10
                                         });

            var agent = new mfLYSyncAgent(syncProvider, clientProvider);

            agent.AddSchema(schemaBuilder1, SyncDirection.Bidirectional,
                            TableCreationOption.UploadExistingOrCreateNewTable, "Group1");

            var tables = new Collection<string> {"test1"};
            SyncSchema schema = syncProvider.GetSchema(tables, new SyncSession());

            Assert.AreEqual(1, schema.Tables.Count);
            SyncSchemUtilsFixture.AssertSyncTable(schemaBuilder1, schema.Tables[0]);
        }

        #endregion

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }
    }
}